<template>
	<view>
		<u-toast ref="uToast" />
		<view v-if="show" class="loading_view">
		  <u-loading mode="circle" size="50"></u-loading>
		  <view class="messgae">
			加载中...
		  </view>
		 </view>
		<view class="list" v-else v-for="(v,k) in list" :key="k" @click="onUrl" data-url="/pages/secret/secretView?id=" :data-get="v.s_id">
			<view class="l_img">
				<image :src='v.s_icon'></image>
			</view>
			
			<view class='l_cont'>
				<view class='l_name'>{{v.s_name}}</view>
				<view class='l_descript'>{{v.s_quotations}}</view>
				<view class='pric'>￥{{v.s_money}}</view>
			</view>
			
			<view class="clear"></view>
		</view>
		<view v-if="showError!=''" class='empty'>
			<u-loading mode="circle" v-if='show' size="50"></u-loading>
			<text>{{showError}}</text>
		</view>
	</view>
</template>

<script>
	export default{
		data(){
			return{
				list:[],
				page:1,
				allpage:1,
				show:true,
				showError:''
			}
		},onLoad(){
			this.onList(1);
		},onReachBottom(){
			var page=this.page;
			
			if(page<this.allpage){
				page++;
			}else{
				this.showError='暂无更多课程了~';
				return;
			}
			
			this.onList(page);
		},onPullDownRefresh() {
			// uni.startPullDownRefresh();
			this.show=true;
			
			this.showError='';
		    
			this.onList(1,1);
		},methods:{
			onUrl(e){
				var url=e.currentTarget.dataset.url;
				
				var get=e.currentTarget.dataset.get;
				
				uni.navigateTo({
				    url: url+get
				});
			},
			onList(page=1,type=0){
				var that=this;
				
				this.$request({
					url:"/secret/show",
					data:{page:page},
					success(res){
						if(res.data.code==1){
							if(type==1){
								that.list=[];
							}
							var data=res.data.data;
							
							that.page=data.page;
							
							that.allpage=data.allpage;
							
							for(var i in data.list){
								that.list.push(data.list[i]);
							}
							
							that.show=false;
							
							that.showError='';
							
							if(that.page>=that.allpage){
								that.showError='暂无更多课程了~'
							}
						}else{
							that.show=false;
							
							that.showError=res.data.msg;
						}
					},fail(res){
						that.$refs.uToast.show({
							title: '网络繁忙',
							type:'warning'
						});
					},
					complete(){
						uni.stopPullDownRefresh()
					}
				})
			}
		}
	}
</script>

<style scoped src="../../static/css/secret.css">
</style>

<style scoped>
	.empty{
		padding:20rpx 0;
		text-align: center;
	}
</style>
